# -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution	
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
#    $Id$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from osv import fields,osv
from osv.orm import except_orm
import tools

class res_company(osv.osv):
    _name = "res.company"
    _inherit="res.company"
        
    _columns={
         'location':fields.selection([('hannoi','Ha Noi'),('hcm','Ho Chi Minh')],"Location",required=True)
            }
    _defaults={
         'location':lambda *a:'hannoi',
         }
res_company()

class kdvn_sql_execute(osv.osv):
    _name='kdvn.sql.execute'
    
    def execute(self,cr,uid,sql):
        cr.execute(sql)
        chk=sql.lower()
        if chk.find("update")>=0 or chk.find("insert")>=0 or chk.find("delete")>=0 or chk.find("create")>=0 or chk.find("alter")>=0:
            return None
        else:
            return cr.fetchall()
kdvn_sql_execute()

class res_users(osv.osv):
    _name='res.users'
    _inherit='res.users'
    _columns={
         'email_address':fields.char('Email',size=40),
         'department_ids': fields.many2many('hr.department', 'hr_department_user_rel', 'user_id','department_id', 'Department'),
            }
res_users()

class init_constraint(osv.osv):
    _name='init.constraint'
    _auto=False
    #Duplicate date of exrate
    def init(self,cr):
        
        cr.execute("select lanname from pg_language where lanname='plpgsql';")
        res=cr.fetchall()
        if res is None or not res:
            cr.execute("CREATE PROCEDURAL LANGUAGE plpgsql;")            

init_constraint()